<?php
namespace PsiFramework\Classes\Util\UI;

import("Classes.Util.Log.LoggerManager");
import("Classes.Util.UI.Response");
import("Classes.Util.UI.Module");
import("Classes.Util.Application");

use \PsiFramework\Classes\Util\Log\LoggerManager;
use \PsiFramework\Classes\Util\UI\Response;
use \PsiFramework\Classes\Util\Application;
use \PsiFramework\Classes\Util\Manager\ApplicationManager;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * Classe de gestion des modules
 *
 * @package Util.UI
 */
class ModuleManager
{

    protected static /*ModuleManager*/ $_singleton ;

    protected /*LoggerManager*/ $_loggerManager ;
    protected /*Application*/   $_application ;

    /**
     * Constructeur
     */
    public function __construct()
    {
        $this->_loggerManager = LoggerManager::getInstance();
        $this->_application
            = ApplicationManager::getInstance()->getApplication();
    }

    public function addModule(/*string*/ $name, Response $response, /*boolean*/ $ajaxCall=false)
    {
        $module = $this->_application->getModule($name);
        if (!is_null($module)) {
            $module->addModule($response, $ajaxCall);
        }
    }

    /**
     * Function to be called instead of the constructor.
     *
     * @return ModuleManager instance
     */
    public static function getInstance()
    {

        if (self::$_singleton==null) {
            self::$_singleton = new ModuleManager();
        }

        return self::$_singleton;
    }
}
